package cn.mzy.oneway;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

//消息发送者
public class Producer {

    public static void main(String[] args) {
        try {
            // 实例化消息生产者Producer
            DefaultMQProducer producer = new DefaultMQProducer("oneway_group_name");
            // 设置NameServer的地址
            producer.setNamesrvAddr("localhost:9876");
            // 启动Producer实例
            producer.start();
            //构建消息
            Message message = new Message("oneway_order_topic", "oneway_pet_tag", ("我是消息").getBytes(StandardCharsets.UTF_8));
            producer.sendOneway(message);
            System.out.println("发送成功");
            // 如果不再发送消息，关闭Producer实例。
            producer.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}